﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 第三次课堂作业
{
    class Triangle : Shape
    {
        private double s1, s2, s3;

        public Triangle(double s1,double s2,double s3)
        {
            this.s1 = s1;
            this.s2 = s2;
            this.s3 = s3;
            if (isLegal())
                Console.WriteLine("This is a Triangle. The area is " + Area);
            else
                Console.WriteLine("The input is not legal. Make another Instance.");
        }

        public override double Area
        {
            get
            {
                double p = (s1 + s2 + s3) / 2;
                return Math.Sqrt(p * (p - s1) * (p - s2) * (p - s3));
            }
        }

        public override bool isLegal()
        {
            double p = (s1 + s2 + s3) / 2;
            if (s1 <= 0 || s2 <= 0 || s3 <= 0)
                return false;
            else if (p * (p - s1) * (p - s2) * (p - s3) <= 0)
                return false;
            return true;
        }

    }
}
